﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Coater.Helper.Modbus
{
    /// <summary>
    /// modbus协议接口
    /// </summary>
    public interface IModbusHelper
    {
        /// <summary>
        /// 是否已连接
        /// </summary>
        public bool IsOpen { get; }

        /// <summary>
        /// 连接
        /// </summary>
        public void Open();

        /// <summary>
        /// 关闭
        /// </summary>
        public void Close();

        /// <summary>
        /// 01 读取线圈
        /// </summary>
        public bool[] ReadCoils(byte slaveAddress, ushort startAddress, ushort numberOfPoints);

        /// <summary>
        /// 05 写单个线圈
        /// </summary>
        public bool WriteSingleCoil(byte slaveAddress, ushort coilAddress, bool value);

        /// <summary>
        /// 0F 写多个线圈
        /// </summary>
        public bool WriteMultipleCoils(byte slaveAddress, ushort startAddress, bool[] data);

        /// <summary>
        /// 02 读取离散量输入
        /// </summary>
        public bool[] ReadInputs(byte slaveAddress, ushort startAddress, ushort numberOfPoints);

        /// <summary>
        /// 04 读取输入寄存器
        /// </summary>
        public byte[] ReadInputRegisters(byte slaveId, ushort start, ushort length);

        /// <summary>
        /// 03 读保持寄存器
        /// </summary>
        public byte[] ReadHoldingRegisters(byte slaveId, ushort start, ushort length);

        /// <summary>
        /// 06 写单个保持寄存器
        /// </summary>
        public bool WriteSingleRegister(byte slaveAddress, ushort registerAddress, ushort value);

        /// <summary>
        /// 10 写多个保持寄存器
        /// </summary>
        public bool WriteMultipleRegisters(byte slaveAddress, ushort startAddress, ushort[] data);


    }
}
